#fluent数据轴向处理，3D
#by zyp
import numpy as np
import pandas as pd
import math


#读取dat文件数据
name='void20'
dat=np.loadtxt(name,dtype=float,skiprows=1,delimiter=',')               #指定文件名称（与脚本在同一目录下）
dat_2=np.loadtxt(name,dtype=str,skiprows=0,delimiter=',')               #指定文件名称（与脚本在同一目录下）



total_rows=dat.shape[0]
total_cols=dat.shape[1]
dat=np.delete(dat,0,axis=1)   #删除第一列
high_col=1    #z为高度
out_datmin=5    #剔除数据
out_datmax=5.2   #剔除数据



dat=dat[dat[:,high_col].argsort()]    #按z轴从小到大排列

point_number=20         #划分多少个数据点
y_min=dat[0,high_col]        #高度min
y_max=dat[-1,high_col]          #高度max
physical_quantity=np.zeros((point_number,total_cols-2))
physical_quantity[:,0]=np.linspace(y_min,y_max,point_number)
interval=((y_max-y_min)/(point_number-1))
interval_use=interval/2

j=3
while j<total_cols-1:
    print(dat_2[0,j+1])
    i = 0
    k = 0
    sum = 0
    count = 0
    while i<total_rows:
        if physical_quantity[k,0]-interval_use<dat[i,high_col]<=physical_quantity[k,0]+interval_use:
            if out_datmin<=dat[i,high_col]<=out_datmax:
                i+=1
                continue
            else:
                sum=sum+dat[i,j]
                count+=1
                i+=1
        else:
            aver=sum/count
            physical_quantity[k,j-2]=aver
            k+=1
            sum=0
            count=0

    j+=1


import matplotlib.pyplot as plt
from pylab import mpl
plt.plot(physical_quantity[:,1], physical_quantity[:, 0], label='catvof',color='blue')
plt.legend()
plt.show()

np.savetxt(name+".csv", physical_quantity, delimiter=',')
print('finish')
